package cate.game.admin.menu.tools;

import cate.common.table.d.GDChat;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;
import cate.game.chat.ChatFacade;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;

@Slf4j
public class ToolsMenu extends MenuSetup {

    public ToolsMenu(GameBody game) {
        super("工具类");

        reg(game, "输出统计到聊天框", 0, "", (role, params) -> {
            String res = role.getSystem().gmLogsStr();
            ChatFacade.sendPublicFromClient(role, GDChat.Channel.WORLD, 0, res, new ArrayList<>());
        });

        reg(game, "游戏服保存数据并关服", 0, "【参数】：无", (role, params) -> {
            //int cmd = toInt(params, 0, 0);
            game.process.getAll().forEach(g -> {
                String tag = g.config.srvId + "-" + g.config.gs.getName();
                log.info("正在关闭 {}", tag);
                g.shutdown();
                log.info("已关闭 {}", tag);
            });
            log.info("要退出啦!!!!!!!!!!!!!!!!!");
            Runtime.getRuntime().halt(0);
        });

        reg(game, "屏蔽字库replace", 1, "【参数1】：原始文本", (role, params) -> {
            String origin = toString(params, 0, "OK，习近平永远万岁");
            //origin = "<data type=2 param={\"type\":2,\"tid\":10111,\"uid\":\"6229d34ef8d30858c1a0ba3d\",\"num\":1,\"level\":0,\"exp\":0,\"grade\":0,\"gradeHeroTid\":0,\"camp\":0,\"_tpl\":{\"id\":\"10111\",\"name\":600101,\"icon\":\"1111\",\"camp\":0,\"job\":1,\"type\":1,\"quality\":1,\"suit\":0,\"exp\":30,\"attr\":\"3:43#110:43\",\"desc\":601101,\"campBaseRate\":0.25,\"remarkCost\":\"3:100001:10\",\"markCost\":null}} name=黑铁剑><data>";
            log.info("收到的原始字符串是:{}", origin);
            long beginTime = System.currentTimeMillis();
            String result = game.tools.sensitiveWords.replace(origin);
            log.info("处理过后的字符串是：{}", result);
            long costTime = System.currentTimeMillis() - beginTime;
            game.notice.message(role, ""+result+" 耗时"+costTime+"ms");
        });
    }
}
